/**
 *
 */
package de.cbf.cam.dsa.item.ui.composites;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.widgets.Composite;

import de.cbf.cam.dsa.item.interfaces.ICompositeEdit;
import de.cbf.util.ui.listener.IUiChangeListener;
import de.cbf.util.ui.listener.UiChangeEvent;

/**
 * @author salter
 *
 */
public abstract class AbstractCompositeEdit extends Composite implements ICompositeEdit {

	protected List<IUiChangeListener> uiChangeListeners = new ArrayList<IUiChangeListener>();
	/**
	 * @param parent
	 * @param style
	 */
	public AbstractCompositeEdit(Composite parent, int style) {
		super(parent, style);
		buildComposite(this);
	}

	protected  abstract void buildComposite(Composite thisComposite);

	@Override
	public void registerUIChangedListener(IUiChangeListener viewListener) {
		uiChangeListeners.add(viewListener);
	}

	@Override
	public void unRegisterUIChangedListener(IUiChangeListener viewListener) {
		uiChangeListeners.remove(viewListener);
	}

	protected void notifyUiChange(int index, Object value){
		UiChangeEvent event = new UiChangeEvent(this);
		event.setIndex(index);
		event.setNewValue(value);
		for (IUiChangeListener listener : uiChangeListeners) {
			listener.uiChanged(event);
		}
	}

	protected void signalCommand(int index, Object... parameters){
		for (IUiChangeListener listener : uiChangeListeners) {
			listener.commandIssued(index, parameters);
		}
	}

}
